package com.huateng.springcloud.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2 config
 *
 * @author Evan
 * @create 2021/6/13 15:20
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    //http://localhost:30001/swagger-ui.html 原网页
    //http://localhost:30001/doc.html 简洁网页

    //配置swagger2核心配置docket
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.huateng.springcloud.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder().title("SpringCloud 平台接口Api")
                .contact(new Contact("SpringCloud", "https://swagger.io",
                        "swagger@163.com"))
                .description("SpringCloud 平台接口Api文档")
                .version("1.0.0")
                .termsOfServiceUrl("https://swagger.io")
                .build();
    }

}
